<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">从其他项目引入-基准费用信息</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>
<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var choose_type = getQueryVariable('choose_type');
    if(choose_type === undefined || choose_type === false){
        choose_type = 'radio';
    }else{
        choose_type = 'checkbox';
    }
    var parent_type = getQueryVariable('type');
    var parent_page = getQueryVariable('page');
    var parent_enginid = getQueryVariable('enginid');

    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        $("#cols_table").hide();
        $("#export_table").hide();
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_main_mark_yin),where: {type:parent_type,enginid:parent_enginid}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: ['', '', ''],filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,parseData: function(res){

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            ,cols: [[
                {type:choose_type,fixed:'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field: 'name', title: '项目名称'}
                ,{field: 'listnum', title: '基准费用数量'}
            ]]
            ,done : function(res, curr, count){
                $(".layui-table-tool").remove()
                soulTable.render(this);
            }
        });
        listTableSearch(form, table);


        $('#submit').on('click', function () {
            var checkStatus = layui.table.checkStatus('datalist');
            var data = checkStatus.data;
            if(data.length < 1){
                facade.error("请选择数据");return false;
            }
            if(data[0].list.length < 1){
                facade.error("当前选择项目无基准费用信息");return false;
            }

            if(parent_page == 'mark'){
                layer.confirm('此操作在保存后会清除当前数据，是否继续？',function(index){
                    basetypeArr = parent.basetypeArr

                    var editStr = '';
                    var list = data[0].list;
                    for (var i=0;i<list.length;i++){
                        editStr += '<tr>';
                        editStr += '<td class="td1" style="width: 45px">'+(i + 1)+'</td>';
                        editStr += '<td class="td2"><select class="layui-select basetype">';
                        editStr += '<option value="">请选择</option>';
                        var this_basetype = basetypeArr[parent_type];
                        for(var j=0;j<this_basetype.length;j++){
                            if(list[i].basetype == this_basetype[j].name){
                                editStr += '<option value="'+this_basetype[j].name+'" selected>'+this_basetype[j].name+'</option>';
                            }else{
                                editStr += '<option value="'+this_basetype[j].name+'">'+this_basetype[j].name+'</option>';
                            }
                        }
                        editStr += '</select></td>';
                        editStr += '<td class="td3"><input type="text" class="layui-input name" listid="0" source="'+list[i].source+'" value="'+list[i].name+'"></td>';
                        editStr += '<td class="td4"><textarea class="layui-textarea curarea guige">'+list[i].guige+'</textarea></td>';
                        editStr += '<td class="td5"><input type="text" class="layui-input valunit" value="'+list[i].valunit+'"></td>';
                        editStr += '<td class="td6"><input type="text" class="layui-input content_exp" value="'+list[i].content_exp+'"></td>';
                        editStr += '<td class="td7"><input type="number" class="layui-input content" readonly value="'+list[i].content+'"></td>';
                        editStr += '<td class="td8"><input type="number" class="layui-input loss_rate" value="'+list[i].loss_rate+'"></td>';
                        editStr += '<td class="td9"><input type="number" class="layui-input no_price" value="'+list[i].no_price+'">';
                        editStr += '<td class="td10"><input type="number" class="layui-input price" readonly value="'+list[i].price+'"></td>';
                        editStr += '<td class="td11"><input type="text" class="layui-input explain" value="'+list[i].explain+'"></td>';
                        editStr += '<td class="td12">';
                        if(list[i].source > 0){
                            editStr += '<a class="opt_a opt_xuan" onclick="func_opt_xuan(this)">选择</a>';
                            editStr += '<a class="opt_a opt_ru layui-hide" onclick="func_opt_ru(this)">入库</a>';
                            editStr += '<a class="opt_a opt_cha" onclick="func_opt_cha(this)">查看</a>';
                            editStr += '<a class="opt_a opt_qing" onclick="func_opt_qing(this)">清空</a>';
                        }else{
                            editStr += '<a class="opt_a opt_xuan" onclick="func_opt_xuan(this)">选择</a>';
                            editStr += '<a class="opt_a opt_ru" onclick="func_opt_ru(this)">入库</a>';
                            editStr += '<a class="opt_a opt_cha layui-hide" onclick="func_opt_cha(this)">查看</a>';
                            editStr += '<a class="opt_a opt_qing layui-hide" onclick="func_opt_qing(this)">清空</a>';
                        }
                        editStr += '</td>';
                        editStr += '<td class="td13"></td>';
                        editStr += '</tr>';
                    }
                    $('#list_list', parent.document).html(editStr);
                    parent.render_from();
                    parent.update_refresh_row_func();

                    layer.close(index);
                    layer_close();
                });
                return false;
            }else{
                var str = '<button type="button" class="layui-btn layui-btn-sm btn-dark" key="'+data[0].id+'"><span class="choose_content">'+data[0].name+'('+data[0].accnum+')'+'' +
                    '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                $("#"+parent_dom , parent.document).html(str);
                parent.formValid(parent_dom);
            }

            layer_close();
        });

    });
</script>
</body>
</html>
